<template>
  <div>
    <div class="mui-card">
      <div class="mui-card-content">
        <lunbo :lunBoList="lunBoList"></lunbo>
      </div>
    </div>

    <div class="mui-card">
      <div class="mui-card-header">{{ goodsinfo.title }}</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p class="price">
            市场价：
            <del>￥{{ goodsinfo.market_price }}</del>&nbsp;&nbsp;销售价：
            <span class="now_price">￥{{ goodsinfo.sell_price }}</span>
          </p>
          <p>
            购买数量：
            <numbox @getcount="getSelectedCount" :max="goodsinfo.stock_quantity"></numbox>
          </p>
          <p>
            <mt-button type="primary" size="small">立即购买</mt-button>
            <mt-button type="danger" size="small" @click="addToShopCar">加入购物车</mt-button>
          </p>
        </div>
      </div>
    </div>

    <div class="mui-card">
      <div class="mui-card-header">商品参数</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p>商品货号：{{ goodsinfo.goods_no }}</p>
          <p>库存情况：{{ goodsinfo.stock_quantity }}件</p>
          <p>上架时间：{{ goodsinfo.add_time | dateFormat }}</p>
        </div>
      </div>
      <div class="mui-card-content">
        <button
          class="mint-button mint-button--primary mint-button--large is-plain"
          style="margin-bottom:15px"
        >
          <!---->
          <label class="mint-button-text">图文介绍</label>
        </button>
        <button
          @click="getcomment(this.id)"
          class="mint-button mint-button--danger mint-button--large is-plain"
          style="margin-bottom:25px"
        >
          <label class="mint-button-text">商品评价</label>
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import lunbo from "../slide/slide";
import numbox from "../slide/goodsinfo_numbox";
export default {
  data() {
    return {
      id: this.$route.params.id,
      lunBoList: [],
      goodsinfo: {},
      selectedCount: 1
    };
  },
  created() {
    this.getlunbo();
    this.getGoodsInfo();
  },
  methods: {
    getlunbo() {
      this.$ax
        .get("api/getthumimages/" + this.id)
        .then(result => {
          result.data.message.forEach(item => {
            item.img = item.src;
          });
          this.lunBoList = result.data.message;
          // console.log(result.data.message);
        })
        .catch(err => {});
    },
    getGoodsInfo() {
      // 获取商品的信息
      this.$http.get("api/goods/getinfo/" + this.id).then(result => {
        if (result.body.status === 0) {
          this.goodsinfo = result.body.message[0];
          console.log(result.body.message[0]);
        }
      });
    },
    addToShopCar() {
      var goodsInfo = {
        id: this.id,
        count: this.selectedCount,
        price: this.goodsinfo.sell_price,
        selected: true
      };
      this.$store.commit('addToCar',goodsInfo)
    },

    getcomment(id) {},
    getSelectedCount(count) {
      // 当子组件把 选中的数量传递给父组件的时候，把选中的值保存到 data 上
      this.selectedCount = count;
      // console.log("父组件拿到的数量值为： " + this.selectedCount);
    }
  },
  components: {
    lunbo,
    numbox
  }
};
</script>

<style scoped>
</style>
